﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Ordonnance
{
    public partial class FormEdit : Form
    {
        public List<String> fldTextL = new List<String>();
        public TextBox[] txb;
        public bool bOk = false;
       
        public String NameOk = "";
        public Dictionary<String, String> el = new Dictionary<string, string>();
        
        public FormEdit()
        {
            InitializeComponent();
        }

        private void FormEdit_Shown(object sender, EventArgs e)
        {
            bOk = false;
            fldTextL.Clear();
            txb = new TextBox[el.Count];
            int i = 0;
            foreach (KeyValuePair<string, string> kvp in el)
            {
                txb[i] = new TextBox();
                txb[i].Location = new System.Drawing.Point(128, 18 + i * 26);
                txb[i].Size = new System.Drawing.Size(144, 20);
                txb[i].TabIndex = i+1;
                txb[i].Text = kvp.Value;

                Label lbl = new Label();
                lbl.AutoSize = true;
                lbl.Location = new System.Drawing.Point(9, 21 + i * 26);
                lbl.Text = kvp.Key;
                Controls.Add(txb[i]);
                Controls.Add(lbl);
                i++;
            }
            txb[0].Focus();
            btnOk.TabIndex = el.Count + 1;
            btnOk.Text = NameOk;
            btnOk.Location = new Point(12, 18 + el.Count * 26);
            btnCancel.TabIndex = el.Count + 2;
            btnCancel.Location = new Point(197, 18 + el.Count * 26);
            Height = 76 + el.Count * 26;
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            bOk = true;
            Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            bOk = false;
            Close();
        }

        private void FormEdit_FormClosing(object sender, FormClosingEventArgs e)
        {
            for(int i=0;i<Controls.Count;i++)
                if (Controls[i].GetType() == typeof(TextBox) || Controls[i].GetType() == typeof(Label))
                {
                    Controls.RemoveAt(i);
                    i--;
                }
        }
    }
}
